public class Practice3 {

    //https://www.nowcoder.com/practice/c43a0d72d29941c1b65c857d8ac9047e?tpId=196&tqId=39317&ru=/exam/oj
    //考察双指针, 虽然跑过但是掌握没那么好, 明天需要强化一下
    public String compressString (String param) {
        // write code here
        StringBuilder sb = new StringBuilder();
        char[] s = param.toCharArray();
        int n = s.length;
        if(n < 2){
            return param;
        }

        int left = 0;
        for(int right = 0;right < n;right++){
            while(right < n && s[left] == s[right]){
                right++;
            }
            sb.append(s[left]);
            if(right - left > 1){
                sb.append(right - left);
            }
            left = right;
        }
        if(s[n - 1] != s[n - 2]){
            sb.append(s[n - 1]);
        }


        return sb.toString();
    }
    public static void main(String[] args) {

    }
}
